﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ExWarehouse</title>
    @*Easyui需要引入的文件*@
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link href="~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.4.5/themes/icon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script type="text/javascript" src="~/Content/Site.js"></script>
    <script src="~/Content/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function () {
            //初始化datagrid
            InitGrid();
            InitDialog();
            InitControl();
            $('#btnReload').click(function () {
                $("#grid").datagrid("reload");
            });
            //ajax提交修改表单
            $('#ok').click(function () {
                $('#errdiv').removeClass('dis');
                $('#form').submit();
            });
            $('#cancel').click(function () {
                $('#dd').dialog('close');
            });
            $('#add').click(function () {
                $('#form')[0].reset();
                $('#key').val(0);
                $('#EWID').attr('placeholder', '编号：EX+日期+序号');
                $('#EWID').removeAttr('disabled');
                $('#IsEW').removeAttr('disabled');
                $('#EWWay').removeAttr('disabled');
                $('#dd').dialog('open');
            });
            $('#edit').click(function () {
                $('#EWID').attr('disabled', 'disabled');
                $('#EWWay').attr('disabled', 'disabled');
                getAjax("../PSS_ExWarehouse/LoadForm",
                        { id: $('#del_id').val() }, function (data) {
                            var data = eval("(" + data + ")");
                            SetWebControls(data);
                            $('#old_isew').val($('#IsEW').val());
                            if ($('#IsEW').val() == 1)
                                $('#IsEW').attr('disabled', 'disabled');
                        });
                $('#key').val(1);
                $('#dd').dialog('open');
            });

            $('#del').click(function () {
                getAjax("../PSS_ExWarehouse/Del", { id: $('#del_id').val() }, function (data) {
                    if ($('#del_id').val() == null || $('#del_id').val() == "")
                        return false;
                    if (data) {
                        $.messager.alert('提示', '操作成功！');
                        $('#dd').dialog('close');
                        $("#grid").datagrid("reload");
                        return true;
                    }
                    else {
                        $.messager.alert('提示', '操作失败!');
                        return false;
                    }
                });
            });
        });

        //实现对DataGird控件的绑定操作
        function InitGrid() {
            $('#grid').datagrid({
                url: '../PSS_ExWarehouse/LoadList',
                singleSelect: true,
                fit: true,
                nowrap: true,//单行显示
                autoRowHeight: false,
                striped: false,     //斑马纹
                collapsible: true,      //可折叠
                pagination: true,
                pageSize: 20,
                border: false,
                fitColumns: true,       //自适应列宽
                rownumbers: true,
                columns: [[
                     { title: '出库单号', field: 'EWID' },
                     { title: '出库方式', field: 'Name' },
                     {
                         title: '出库状态', field: 'IsEW',
                         formatter: function (value, row, index) {
                             if (value == 1)
                                 return "已出库";
                             else
                                 return "未出库";

                         }
                     },
                     {
                         title: '出库时间', field: 'EWDate',
                         formatter: function (value, row, index) {
                             if (value != null) {
                                 var date = value.split(' ');
                                 return date[0];
                             }
                             else
                                 return "此单还未出库";

                         }
                     },
                     { title: '操作工号', field: 'OperateNo' },
                     {
                         title: '创建日期', field: 'OperateDate',
                         formatter: function (value, row, index) {
                             var date = value.split(' ');
                             return date[0];
                         }
                     },

                     { title: '备注', field: 'Remark' },
                ]],
                toolbar: '#tb',
                onDblClickRow: function (rowIndex, rowData) {
                    addTab('出库详单-' + rowData['EWID'], '../PSS_ExWarehouseDetail/ExWarehouseDetail?EWID=' + rowData['EWID']);
                },
                onClickRow: function (index, row) {
                    $('#del_id').val(row['EWID']);
                }
            })
            var p = $('#grid').datagrid('getPager');
            $(p).pagination({
                beforePageText: '第',
                afterPageText: '页   共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });
        };

        //初始化对话框
        function InitDialog() {
            $('#dd').dialog({
                title: '修改信息',
                width: 300,
                height: 320,
                top: ($(window).height() - 320) * 0.5,      //居中
                left: ($(window).width() - 300) * 0.5,
                closed: true,
                cache: false,
                modal: true,
                buttons: '#dlg-buttons'
            });
        }

        //绑定供货单位下拉框
        function InitControl() {
            var dataJson = "";
            getAjax("/PSS_ExWarehouse/LoadSelectExwarehourseMode", null, function (data) {
                datajson = eval("(" + data + ")");
                $.each(datajson, function (i) {
                    $("#EWWay").append($("<option></option>").val(datajson[i].ID).html(datajson[i].Name));
                });
            })
        }
    </script>
    <script>
        //表单验证和提交
        $(function () {
            $('#form').validate({
                rules: {
                    EWID: {
                        required: true
                    },
                    EWWay: {
                        required: true
                    }
                },
                messages: {
                    EWID: "出库单号不能为空！",
                    IWWay: "出库方式不能为空！"
                },
                errorLabelContainer: '#errdiv>ul',
                wrapper: 'li',
                submitHandler: function (form) {
                    var postData = GetWebControls("#form");
                    getAjax("/PSS_ExWarehouse/AcceptClick",
                        postData, function (data) {
                            if (data == 1) {
                                //此处可以优化，提示消息可更美观。
                                alert("操作成功！");
                                $('#dd').dialog('close');
                                $("#grid").datagrid("reload");
                                return true;
                            }
                            else if (data == -1) {
                                alert("已存在该记录或单号重复，请重新填写！");
                                return false;
                            }
                            else {
                                alert("操作失败！"); return false;
                            }
                        });
                },
                invalidHandler: function (form, validator) {  //不通过回调
                    return false;
                }
            });
        });
    </script>
    <style>
        .dis {
            display: none;
        }

        .td_col-180 {
            width: 180px;
        }

        .td_col-185 {
            width: 185px;
        }
    </style>
</head>
<body style="margin:2px;padding:0">
    <div>
        <input id="del_id" type="hidden" name="del_id" value="" />
        <div style="position:fixed;width:100%;height:100%">
            <div id="tabs" class="easyui-tabs" data-options="fit:true,border:false,plain:true">
                <div title="出库单" style="text-align:center;">
                    <table id="grid"></table>
                </div>
            </div>

        </div>
        <div id="tb" style="padding:3px">
            <a id="add" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
            <a id="edit" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改</a>
            <a id="del" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">刷新</a>
        </div>
    </div>
    <div id="dd" class="easyui-dialog">
        <form id="form" name="form" method="post">
            <input id="key" type="hidden" value="" />
            <input id="old_isew" type="hidden" value="" />
            <table style="margin:8px">
                <tr>
                    <td>出库单号:</td>
                    <td><input type="text" id="EWID" name="EWID" class="td_col-180" value="" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>出库方式:</td>
                    <td><select id="EWWay" name="EWWay" class="td_col-185" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>出库状态:</td>
                    <td>
                        <select id="IsEW" name="IsEW" class="td_col-185">
                            <option value="0">未出库</option>
                            <option value="1">已出库</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>出库日期:</td>
                    <td><input type="text" id="EWDate" name="EWDate" value="" class="td_col-180" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>操作工号:</td>
                    <td><input type="text" id="OperateNo" name="OperateNo" value="" class="td_col-180" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>操作日期:</td>
                    <td><input type="text" id="OperateDate" name="OperateDate" value="" class="td_col-180" disabled="disabled" /></td>
                </tr>
                <tr>
                    <td>备注:</td>
                    <td><textarea id="Remark" name="Remark" class="td_col-180"></textarea></td>
                </tr>
            </table>
            <div class="errdiv" id="errdiv">
                <ul></ul>
            </div>
            <div id="dlg-buttons">
                <a id="ok" href="#" class="easyui-linkbutton" iconcls="icon-ok">确定</a>
                <a id="cancel" href="#" class="easyui-linkbutton" iconcls="icon-cancel">取消</a>
            </div>

        </form>
    </div>
</body>
</html>
